library(ggplot2)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(viridis)
## Loading required package: viridisLite
library(stringr)

casestudy2 = read.csv(".//CaseStudy2-data.csv") #casestudy2-data.csv

#Attrition by Department
ggplot(casestudy2, aes(x=as.factor(Department), fill=Attrition))+
  geom_bar(aes( y=..count../tapply(..count.., ..x.. ,sum)[..x..]), position="stack" , width=0.5) +
  geom_text(aes( y=..count../tapply(..count.., ..x.. ,sum)[..x..], label=scales::percent(..count../tapply(..count.., ..x.. ,sum)[..x..]) ),
            stat="count", position=position_stack(0.9), vjust=0.5)+
  xlab('Department') +
  ylab('Percent of Attrition')+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))+
  theme(axis.text = element_text(size = 7))

casestudy2$Attritioncalc=case_when(
  casestudy2$Attrition =='Yes'  ~ 1,
   TRUE ~ 0
)

#summary
er<-casestudy2 %>% group_by(Department) %>% summarize(meanincome = mean(MonthlyIncome), calcAttrition = (sum(Attritioncalc)/n()), Employees = n()) %>% arrange(desc(Employees))
er 
## # A tibble: 3 × 4
##   Department             meanincome calcAttrition Employees
##   <chr>                       <dbl>         <dbl>     <int>
## 1 Research & Development      6173.         0.133       562
## 2 Sales                       6789.         0.216       273
## 3 Human Resources             6776.         0.171        35
ggplot() +
  geom_bar( data=er, aes(x=Department, color=Employees, size=calcAttrition, alpha=0.5)) +
    scale_size(range = c(1, 10), name="Attrition %")+
    scale_color_viridis(option="viridis",  name="Employees" ) +
  ggtitle("Attrition by Department")

#Attrition % by Job Role and Department
#summary table
er<-casestudy2 %>% group_by(Department, JobRole) %>% summarize(meanincome = mean(MonthlyIncome), calcAttrition = (sum(Attritioncalc)/n()), Employees = n()) %>% arrange(desc(Employees))
## `summarise()` has grouped output by 'Department'. You can override using the `.groups` argument.
er 
## # A tibble: 11 × 5
## # Groups:   Department [3]
##    Department             JobRole             meanincome calcAttrition Employees
##    <chr>                  <chr>                    <dbl>         <dbl>     <int>
##  1 Sales                  Sales Executive          6892.        0.165        200
##  2 Research & Development Research Scientist       3259.        0.186        172
##  3 Research & Development Laboratory Technic…      3222.        0.196        153
##  4 Research & Development Manufacturing Dire…      7505.        0.0230        87
##  5 Research & Development Healthcare Represe…      7435.        0.105         76
##  6 Sales                  Sales Representati…      2653.        0.453         53
##  7 Research & Development Research Director       15750.        0.0196        51
##  8 Human Resources        Human Resources          3285.        0.222         27
##  9 Research & Development Manager                 17139.        0.0870        23
## 10 Sales                  Manager                 16719.        0.1           20
## 11 Human Resources        Manager                 18560         0              8
#graph
ggplot() +
  geom_polygon(data =  er, aes(x=Department, y = JobRole),color = "white", fill="grey", alpha=0.5) +
  geom_point( data=er, aes(x=Department, y=JobRole, color=Employees, size=calcAttrition, alpha=0.5)) +
  scale_color_viridis(option="viridis",  name="Employees" ) +
  scale_size(range = c(1, 10), name="Attrition %")+
  ggtitle("Attrition by Role")

#Attrition % by Job Level and Department
#summary
er<-casestudy2 %>% group_by(Department, JobLevel) %>% summarize(meanincome = mean(MonthlyIncome), calcAttrition = (sum(Attritioncalc)/n()), Employees = n()) %>% arrange(desc(Employees))
## `summarise()` has grouped output by 'Department'. You can override using the `.groups` argument.
er 
## # A tibble: 15 × 5
## # Groups:   Department [3]
##    Department             JobLevel meanincome calcAttrition Employees
##    <chr>                     <int>      <dbl>         <dbl>     <int>
##  1 Research & Development        1      2793.        0.219        256
##  2 Research & Development        2      5435.        0.0542       166
##  3 Sales                         2      5678.        0.146        144
##  4 Research & Development        3     10248.        0.0909        77
##  5 Sales                         3      9331.        0.189         53
##  6 Sales                         1      2519.        0.48          50
##  7 Research & Development        4     15374.        0.0256        39
##  8 Research & Development        5     19304.        0.0833        24
##  9 Human Resources               1      2691.        0.261         23
## 10 Sales                         4     14863.        0.105         19
## 11 Sales                         5     18965.        0.286          7
## 12 Human Resources               5     19207.        0              6
## 13 Human Resources               2      4982.        0              2
## 14 Human Resources               3      8412.        0              2
## 15 Human Resources               4     16618         0              2
#graph
ggplot() +
  geom_point( data=er, aes(x=Department, y=JobLevel, color=Employees, size=calcAttrition,  alpha=0.5)) +
  scale_color_viridis(option="viridis",  name="Employees" ) +
  scale_size(range = c(1, 10), name="Attrition %")+
  ggtitle("Attrition by Job Level")

Including Plots

You can also embed plots, for example:

## Loading required package: lattice
library(e1071)

clean_casestudy2 = data.frame(   
  Attrition=casestudy2$Attrition,
  Age = scale(casestudy2$Age), 
  JobInvolvement=scale(casestudy2$JobInvolvement),
  JobLevel=scale(casestudy2$JobLevel),
  Distance=scale(casestudy2$DistanceFromHome),
  StockOptionLevel=scale(casestudy2$StockOptionLevel),
  EnvironmentSatisfaction=scale(casestudy2$EnvironmentSatisfaction),
  RelationshipSatisfaction=scale(casestudy2$RelationshipSatisfaction),
  JobSatisfaction=scale(casestudy2$JobSatisfaction),
  YearSinceLastPromotion=scale(casestudy2$YearsSinceLastPromotion),
  YearsinCurrentRole=scale(casestudy2$YearsInCurrentRole),
  Education=scale(casestudy2$Education)
)
casestudy2.noatt= data.frame(    
  Attrition=casestudy2.noattrition$Attrition,
  Age = scale(casestudy2.noattrition$Age), 
  JobInvolvement=scale(casestudy2.noattrition$JobInvolvement),
  JobLevel=scale(casestudy2.noattrition$JobLevel),
  Distance=scale(casestudy2.noattrition$DistanceFromHome),
  StockOptionLevel=scale(casestudy2.noattrition$StockOptionLevel),
  EnvironmentSatisfaction=scale(casestudy2.noattrition$EnvironmentSatisfaction),
  RelationshipSatisfaction=scale(casestudy2.noattrition$RelationshipSatisfaction),
  JobSatisfaction=scale(casestudy2.noattrition$JobSatisfaction),
  YearSinceLastPromotion=scale(casestudy2.noattrition$YearsSinceLastPromotion),
  YearsinCurrentRole=scale(casestudy2.noattrition$YearsInCurrentRole),
  Education=scale(casestudy2.noattrition$Education))
      
test= casestudy2.noatt
train=clean_casestudy2

#confusion matrix results for each row
numks = 30

masterAcc = matrix(nrow = numks)
masterSens = matrix(nrow = numks)
masterSpec = matrix(nrow = numks)
masterK = matrix(nrow = numks)

data(attrition)
## Warning in data(attrition): data set 'attrition' not found
##    Accuracy Sensitivity Specificity           K 
##   0.8191111   0.8356097   0.3526761  15.5000000
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ tibble  3.1.6     ✓ purrr   0.3.4
## ✓ tidyr   1.1.4     ✓ forcats 0.5.1
## ✓ readr   2.1.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
## x purrr::lift()   masks caret::lift()

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

## 
## Call:
## lm(formula = MonthlyIncome ~ JobLevel + YearsinCurrentRole, data = clean_casestudy2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4981.4  -928.0    71.8   693.6  3751.1 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## (Intercept)         6390.26      47.91 133.382   <2e-16 ***
## JobLevel            4397.74      52.09  84.425   <2e-16 ***
## YearsinCurrentRole   -57.23      52.09  -1.099    0.272    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1413 on 867 degrees of freedom
## Multiple R-squared:  0.9057, Adjusted R-squared:  0.9055 
## F-statistic:  4166 on 2 and 867 DF,  p-value: < 2.2e-16
##         1         2         3         4         5         6         7         8 
##  6267.271 18291.289 10301.484 10175.690  2217.334 10222.863  2233.058  6298.720 
##         9        10        11        12        13        14        15        16 
##  2248.783  6267.271 18212.667  2233.058 10254.311  2264.507  2170.161  6172.925 
##        17        18        19        20        21        22        23        24 
##  6188.650  6298.720  2264.507  6298.720  6267.271  6267.271  6188.650  6267.271 
##        25        26        27        28        29        30        31        32 
##  6298.720 18259.840  6172.925  6267.271 10301.484  2217.334  6188.650  2091.539 
##        33        34        35        36        37        38        39        40 
## 14257.076  2264.507  6298.720  2248.783 10144.241  6267.271 18354.186  2233.058 
##        41        42        43        44        45        46        47        48 
## 14225.627  6188.650  2233.058 18401.359  2264.507  2122.988  6298.720 10222.863 
##        49        50        51        52        53        54        55        56 
##  2264.507  2233.058  2264.507 18275.564  2185.885  6188.650  6188.650  2217.334 
##        57        58        59        60        61        62        63        64 
##  2233.058  2122.988 10301.484  2264.507 10222.863 10222.863  2233.058  2264.507 
##        65        66        67        68        69        70        71        72 
##  2264.507  2233.058  6125.752  2233.058  2233.058  2075.815  2217.334  6235.823 
##        73        74        75        76        77        78        79        80 
##  6298.720  2264.507 10222.863  6172.925 10191.414 14367.146 10222.863  2264.507 
##        81        82        83        84        85        86        87        88 
##  6298.720  6188.650  6251.547  6188.650  6078.579 14319.973  6188.650  2233.058 
##        89        90        91        92        93        94        95        96 
## 10207.138 18369.910  2264.507 10207.138  2264.507  6267.271 18338.462  6047.131 
##        97        98        99       100       101       102       103       104 
## 14178.454  6298.720  2233.058  2201.610  2264.507 10222.863  6267.271  2233.058 
##       105       106       107       108       109       110       111       112 
## 14241.351  2154.437  6188.650 18259.840  6188.650  2233.058  2248.783 14241.351 
##       113       114       115       116       117       118       119       120 
## 10238.587  6298.720  6188.650 10332.933  6251.547  6251.547  2138.712  6125.752 
##       121       122       123       124       125       126       127       128 
## 10222.863  2233.058 10270.036  6188.650  6188.650  6172.925  2233.058  6172.925 
##       129       130       131       132       133       134       135       136 
##  6188.650 14099.832  6298.720  6282.996  6220.098  6235.823  6188.650  6188.650 
##       137       138       139       140       141       142       143       144 
##  2264.507 10222.863  2233.058 10285.760 14115.557  2233.058 10222.863  6235.823 
##       145       146       147       148       149       150       151       152 
##  6125.752  6251.547  2154.437  6267.271  2217.334  6251.547  6282.996  6188.650 
##       153       154       155       156       157       158       159       160 
##  6172.925  6267.271  2264.507  6267.271  6172.925 14257.076 10222.863 10332.933 
##       161       162       163       164       165       166       167       168 
##  6172.925 10222.863  6298.720  6267.271 10191.414  2233.058 14335.697 14351.422 
##       169       170       171       172       173       174       175       176 
##  6157.201  2185.885  6188.650  6188.650 10301.484 10207.138 14162.730  2233.058 
##       177       178       179       180       181       182       183       184 
## 18369.910  2233.058 10207.138  6251.547 10222.863  6188.650  2233.058 10332.933 
##       185       186       187       188       189       190       191       192 
##  2217.334  2233.058  6188.650 14335.697 18338.462  6235.823  6172.925 10301.484 
##       193       194       195       196       197       198       199       200 
##  6188.650  6188.650  2217.334  2264.507  2233.058 14241.351 10238.587  2264.507 
##       201       202       203       204       205       206       207       208 
## 14367.146  6235.823  6094.304  2154.437  2217.334  2154.437  6251.547  6298.720 
##       209       210       211       212       213       214       215       216 
##  2233.058 10222.863 14257.076 18401.359  2264.507  6251.547  2233.058  2248.783 
##       217       218       219       220       221       222       223       224 
##  6298.720 14099.832  2201.610  2185.885  6220.098  6282.996  6220.098  2264.507 
##       225       226       227       228       229       230       231       232 
##  2233.058  2138.712  2264.507  2233.058  6267.271 14194.178  6188.650  2233.058 
##       233       234       235       236       237       238       239       240 
## 14288.524  6267.271 14178.454 10317.209 18307.013  6235.823  2264.507 10159.965 
##       241       242       243       244       245       246       247       248 
## 10191.414 18401.359  2201.610  2233.058  6188.650  2217.334 10191.414  2233.058 
##       249       250       251       252       253       254       255       256 
##  6267.271 14115.557  2248.783  6188.650  2264.507  2264.507 10207.138  2233.058 
##       257       258       259       260       261       262       263       264 
##  2233.058  6267.271 10285.760  2233.058  2264.507  2154.437  2201.610  2248.783 
##       265       266       267       268       269       270       271       272 
##  2217.334  2201.610 14241.351  2264.507  6188.650  6267.271  6188.650  6172.925 
##       273       274       275       276       277       278       279       280 
##  6172.925  6267.271 18165.494 18369.910  2248.783  2154.437  6235.823  6267.271 
##       281       282       283       284       285       286       287       288 
##  6157.201  2060.091  6251.547  6188.650  2170.161  6078.579  2264.507  2233.058 
##       289       290       291       292       293       294       295       296 
## 10222.863  2233.058  2217.334  6172.925  2154.437 10207.138 14257.076  2233.058 
##       297       298       299       300       301       302       303       304 
##  6157.201  6188.650  2233.058  2233.058  6172.925 10207.138  2233.058  6188.650 
##       305       306       307       308       309       310       311       312 
##  2264.507  2233.058  2264.507  2264.507  6188.650  6267.271  6267.271 14272.800 
##       313       314       315       316       317       318       319       320 
##  2233.058  6298.720  6267.271  6298.720  2217.334  6251.547  6235.823  2264.507 
##       321       322       323       324       325       326       327       328 
##  2264.507  2122.988  2201.610  6094.304 14272.800  2248.783 18291.289  6251.547 
##       329       330       331       332       333       334       335       336 
##  6125.752 14257.076 14257.076 10207.138  2217.334 10222.863 18369.910  6188.650 
##       337       338       339       340       341       342       343       344 
##  6267.271  6267.271  6298.720  2264.507  2248.783  2233.058 10301.484  2264.507 
##       345       346       347       348       349       350       351       352 
##  6251.547 14241.351  6267.271  6220.098  2264.507 14257.076 10222.863  6188.650 
##       353       354       355       356       357       358       359       360 
##  6282.996  6267.271 10112.792  6157.201  2201.610  2233.058  6172.925  2060.091 
##       361       362       363       364       365       366       367       368 
## 18118.321  2264.507 18181.218 18291.289 18259.840 14257.076  6172.925  6235.823 
##       369       370       371       372       373       374       375       376 
##  2233.058  6188.650  6251.547 10207.138 10191.414  2201.610  2233.058 14272.800 
##       377       378       379       380       381       382       383       384 
##  2060.091  6298.720  2201.610  2233.058 18369.910  2154.437  6267.271  2264.507 
##       385       386       387       388       389       390       391       392 
##  2264.507 10144.241 10222.863  6267.271  6188.650  2233.058  6267.271  6267.271 
##       393       394       395       396       397       398       399       400 
##  2233.058 10128.517  2248.783  2233.058 14335.697  2233.058  6110.028 10301.484 
##       401       402       403       404       405       406       407       408 
##  6235.823  6251.547  2233.058 10301.484  2185.885 14367.146  6188.650  2154.437 
##       409       410       411       412       413       414       415       416 
## 14241.351 14351.422  2201.610 10207.138  2264.507  6298.720  2233.058  6188.650 
##       417       418       419       420       421       422       423       424 
##  2154.437  2264.507  6172.925 10301.484  6267.271  6125.752  6188.650  2264.507 
##       425       426       427       428       429       430       431       432 
##  6251.547 10332.933  2264.507  2233.058  2233.058  6157.201  6235.823  2233.058 
##       433       434       435       436       437       438       439       440 
##  6251.547  2264.507 10332.933  6188.650  2233.058  2154.437  2233.058  6188.650 
##       441       442       443       444       445       446       447       448 
##  6188.650  2217.334  2264.507  2233.058 18385.635  2185.885  6125.752  6298.720 
##       449       450       451       452       453       454       455       456 
##  6251.547  6188.650  6188.650  2233.058  6188.650  6235.823 14335.697 18275.564 
##       457       458       459       460       461       462       463       464 
##  6298.720  6188.650  2233.058  6235.823  2233.058  2217.334 10301.484  6235.823 
##       465       466       467       468       469       470       471       472 
##  2264.507  2233.058  2233.058  2264.507  6267.271  6267.271  2217.334  2264.507 
##       473       474       475       476       477       478       479       480 
## 10332.933  2185.885  2233.058  6204.374  6298.720  6298.720  2201.610 10159.965 
##       481       482       483       484       485       486       487       488 
##  6251.547  2201.610  6141.477  2233.058 10175.690  6235.823  2264.507  2233.058 
##       489       490       491       492       493       494       495       496 
## 10332.933  6282.996 18369.910 14335.697  6267.271 10207.138  6157.201 14272.800 
##       497       498       499       500       501       502       503       504 
##  2233.058  2233.058  6188.650  6267.271 10191.414  2233.058  2154.437 10191.414 
##       505       506       507       508       509       510       511       512 
## 14099.832  6282.996  2264.507 10301.484  2138.712 18165.494  6188.650 10270.036 
##       513       514       515       516       517       518       519       520 
##  2233.058 10112.792  2233.058  6282.996  2264.507  2217.334  6267.271  2233.058 
##       521       522       523       524       525       526       527       528 
##  2233.058  2248.783 10332.933 18259.840  2264.507 10222.863  6235.823  6220.098 
##       529       530       531       532       533       534       535       536 
##  2201.610  2201.610 10191.414  6298.720  2154.437  6282.996  2154.437  2201.610 
##       537       538       539       540       541       542       543       544 
## 10332.933  2233.058  2217.334  6235.823  6188.650  2138.712  2248.783  6298.720 
##       545       546       547       548       549       550       551       552 
##  2185.885  2122.988 10191.414  6298.720 10207.138  2217.334 18291.289  2248.783 
##       553       554       555       556       557       558       559       560 
##  6282.996  2264.507  6267.271  6298.720  6298.720  2185.885  6172.925  6188.650 
##       561       562       563       564       565       566       567       568 
##  2154.437 14335.697  2233.058 10222.863  2233.058  2217.334  6267.271  6172.925 
##       569       570       571       572       573       574       575       576 
##  6235.823 14194.178  6235.823  2264.507  6188.650  6172.925  6251.547  6220.098 
##       577       578       579       580       581       582       583       584 
##  2264.507  2233.058  6267.271  6298.720  2233.058 14367.146  6298.720  6188.650 
##       585       586       587       588       589       590       591       592 
##  6267.271  6267.271  6125.752  2217.334  2233.058  2233.058  2233.058  6157.201 
##       593       594       595       596       597       598       599       600 
##  2233.058  2170.161 10097.068  6172.925 10175.690  6298.720  6267.271  2264.507 
##       601       602       603       604       605       606       607       608 
##  2264.507  6220.098 10222.863  2138.712  2233.058 14351.422  6251.547  6298.720 
##       609       610       611       612       613       614       615       616 
##  2154.437  2233.058  6188.650  6188.650  2154.437  2264.507 10270.036  6141.477 
##       617       618       619       620       621       622       623       624 
##  2201.610  6251.547 10222.863  2264.507  2264.507  6141.477  2233.058 10332.933 
##       625       626       627       628       629       630       631       632 
##  2264.507  2217.334  6235.823 10175.690 10301.484 10222.863  2233.058 10207.138 
##       633       634       635       636       637       638       639       640 
##  6298.720  2264.507 10332.933  2233.058 14272.800 10222.863  2185.885  2217.334 
##       641       642       643       644       645       646       647       648 
##  2264.507  6235.823 14257.076  2233.058  2264.507 10159.965  2264.507  2233.058 
##       649       650       651       652       653       654       655       656 
##  6094.304  2233.058  2264.507  6188.650 10222.863 10332.933  2233.058  6251.547 
##       657       658       659       660       661       662       663       664 
## 10191.414 14225.627  6235.823  6220.098  6172.925  2217.334 10238.587  2233.058 
##       665       666       667       668       669       670       671       672 
##  6220.098  6267.271 10175.690  2217.334  6235.823 14225.627 10301.484  6267.271 
##       673       674       675       676       677       678       679       680 
##  6267.271  2233.058  2233.058 18338.462  6188.650  6157.201  6267.271  2154.437 
##       681       682       683       684       685       686       687       688 
##  6267.271  2233.058  6267.271 10285.760  2233.058 10207.138 10222.863  2233.058 
##       689       690       691       692       693       694       695       696 
##  2264.507  2107.264  6251.547 10222.863  6298.720  2264.507  6251.547  2233.058 
##       697       698       699       700       701       702       703       704 
## 14335.697  6125.752  2264.507 18369.910  2264.507  6220.098 10301.484  2248.783 
##       705       706       707       708       709       710       711       712 
##  2233.058  6251.547  6282.996  2233.058  2201.610 14272.800 10317.209 14367.146 
##       713       714       715       716       717       718       719       720 
##  2264.507 10191.414 10222.863  2264.507  6251.547  6188.650  6157.201 10222.863 
##       721       722       723       724       725       726       727       728 
## 10222.863  6251.547  2217.334 10207.138  2264.507  6267.271  2201.610  2217.334 
##       729       730       731       732       733       734       735       736 
##  2264.507  2248.783  6298.720  6298.720  2264.507  6267.271  2264.507  6188.650 
##       737       738       739       740       741       742       743       744 
## 14225.627  6282.996  6267.271  6267.271  6267.271 10270.036  6172.925  2233.058 
##       745       746       747       748       749       750       751       752 
##  6251.547  2248.783  2233.058  6157.201  2233.058  2248.783  2233.058  2233.058 
##       753       754       755       756       757       758       759       760 
## 14241.351 10222.863 10285.760  2233.058  6204.374  6267.271  2264.507 18244.116 
##       761       762       763       764       765       766       767       768 
##  2264.507 14147.005  6267.271  6188.650  2233.058  6188.650  2170.161 10332.933 
##       769       770       771       772       773       774       775       776 
##  6251.547  6141.477  6188.650 10128.517 10238.587  2264.507 10207.138  2233.058 
##       777       778       779       780       781       782       783       784 
##  2217.334  2264.507  2154.437  2233.058  2217.334  6188.650  2217.334  6188.650 
##       785       786       787       788       789       790       791       792 
##  6298.720 14335.697 10301.484  6267.271 18401.359  2233.058  6267.271  2233.058 
##       793       794       795       796       797       798       799       800 
## 10270.036 10112.792  6188.650  2138.712 14257.076  2264.507  2248.783  6235.823 
##       801       802       803       804       805       806       807       808 
##  6251.547  6220.098 14225.627 10222.863  6267.271 10207.138  6267.271  2233.058 
##       809       810       811       812       813       814       815       816 
##  2264.507  2233.058  6157.201  2233.058  6267.271 18369.910  2233.058  2107.264 
##       817       818       819       820       821       822       823       824 
##  6298.720 10191.414  2217.334  6298.720  2233.058  6267.271  6188.650  2233.058 
##       825       826       827       828       829       830       831       832 
##  6267.271 18369.910 10332.933  6267.271  2248.783 18322.737  6172.925  2264.507 
##       833       834       835       836       837       838       839       840 
##  2185.885  2248.783 14225.627 10254.311  2201.610  6188.650 10159.965 18244.116 
##       841       842       843       844       845       846       847       848 
##  2264.507 10191.414 14241.351 10222.863  6267.271  6298.720  2264.507 10175.690 
##       849       850       851       852       853       854       855       856 
##  6235.823  2154.437  6267.271  2264.507  6220.098  6251.547  6267.271  2264.507 
##       857       858       859       860       861       862       863       864 
##  2233.058 10191.414  2264.507 10222.863  2264.507 10222.863  6267.271 14335.697 
##       865       866       867       868       869       870 
## 10317.209 10191.414  6267.271  6235.823  2233.058  6267.271

## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
## 
## Attaching package: 'reshape2'
## The following object is masked from 'package:tidyr':
## 
##     smiths
## 
## Call:
## lm(formula = MonthlyIncome ~ JobLevel + YearsinCurrentRole, data = clean_casestudy2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4981.4  -928.0    71.8   693.6  3751.1 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## (Intercept)         6390.26      47.91 133.382   <2e-16 ***
## JobLevel            4397.74      52.09  84.425   <2e-16 ***
## YearsinCurrentRole   -57.23      52.09  -1.099    0.272    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1413 on 867 degrees of freedom
## Multiple R-squared:  0.9057, Adjusted R-squared:  0.9055 
## F-statistic:  4166 on 2 and 867 DF,  p-value: < 2.2e-16
## Warning: 'surface' objects don't have these attributes: 'mode'
## Valid attributes include:
## '_deprecated', 'autocolorscale', 'cauto', 'cmax', 'cmid', 'cmin', 'coloraxis', 'colorbar', 'colorscale', 'connectgaps', 'contours', 'customdata', 'customdatasrc', 'hidesurface', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'legendgroup', 'legendgrouptitle', 'legendrank', 'lighting', 'lightposition', 'meta', 'metasrc', 'name', 'opacity', 'opacityscale', 'reversescale', 'scene', 'showlegend', 'showscale', 'stream', 'surfacecolor', 'surfacecolorsrc', 'text', 'textsrc', 'type', 'uid', 'uirevision', 'visible', 'x', 'xcalendar', 'xhoverformat', 'xsrc', 'y', 'ycalendar', 'yhoverformat', 'ysrc', 'z', 'zcalendar', 'zhoverformat', 'zsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'